package com.pw.study.flink.source

import org.apache.flink.streaming.api.functions.source.SourceFunction

import scala.util.Random

class MyWordSource extends SourceFunction[String] {
  var isSwitch: Boolean = true

  override def run(ctx: SourceFunction.SourceContext[String]): Unit = {
    val str = "How about one year olde My bitthday past a couple days and there is something what I thought Among the main reasons for delaying"
    val line: Array[String] = str.split(" ")
    val random = new Random()
    while (isSwitch) {
      val len: Int = random.nextInt(line.length)
      ctx.collect(line(len))
      println("line: " + line(len))
      Thread.sleep(400)
    }
  }

  override def cancel(): Unit = {
    isSwitch = false
  }
}
